﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TS_XY_Train_Repaire.UserCon.Locomotive
{
    public partial class Plane : DevExpress.XtraEditors.XtraForm
    {
        public Plane()
        {
            InitializeComponent();
        }
        public string name = "";
        public string f_id = "";
        private void btok_Click(object sender, EventArgs e)
        {
            int type = 0;
            if (rb1.Checked)
            {
                type = 1;
            }
            if (rb2.Checked)
            {
                type = 2;
            }
            if (rb3.Checked)
            {
                type = 3;
            }
            if (name == "add")
            {
                string sql = "insert into TS_TR_PS_Loco_Repair_Plane_Main (f_name,f_deep,f_level,f_stime,f_etime,f_type,f_state,f_workerid) values('" + tbname.Text.Trim() + "',0,',','" + dt1.Value + "','" + dt2.Value + "'," + type + ",0," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ")";
                try
                {
                    TS_Win_Class.MySqlCom(sql);
                    MessageBox.Show("添加完成");
                    this.DialogResult= DialogResult.OK;
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            else if (name == "upd") {
                string sql = "update TS_TR_PS_Loco_Repair_Plane_Main set f_name='"+tbname.Text.Trim()+"',f_stime='"+dt1.Value+"',f_etime='"+dt2.Value+"',f_type="+type+" where f_id="+f_id;
                try
                {
                    TS_Win_Class.MySqlCom(sql);
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }

        private void Plane_Load(object sender, EventArgs e)
        {
            if (name == "add") 
            { }
            else if (name == "upd") 
            {
                //MessageBox.Show(f_id);
                DataTable dt = TS_Win_Class.GetFilledDataTable("select * from TS_TR_PS_Loco_Repair_Plane_Main where f_id="+f_id);
                
                tbname.Text = dt.Rows[0]["f_name"].ToString();
                dt1.Value =Convert.ToDateTime( dt.Rows[0]["f_stime"].ToString());
                dt2.Value =Convert.ToDateTime( dt.Rows[0]["f_etime"].ToString());
                int type = Convert.ToInt32(dt.Rows[0]["f_type"].ToString());
                if (type == 0) 
                {
                    rb0.Checked = true;
                }
                else if (type == 1) { rb1.Checked = true; } else if (type == 2) { rb2.Checked = true; } else { rb3.Checked = true; }
            } else if (name == "del") { }
        }

        private void btcancer_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
